//
// File:	Singleton.hpp
// Author:	Thomas TISSOT-DUPONT
// Login:	<thomas.tissotdupont@free.fr>
//
// Created:	14/04/2010 at 13:52:09
// Purpose:	
//

#ifndef SINGLETON_HPP
#define SINGLETON_HPP

//------------------------------------------------------------------
// Singleton Class
//------------------------------------------------------------------
template <typename T>
class Singleton
{
protected:
					Singleton();
	virtual			~Singleton();

private:
					Singleton(const Singleton<T> &);

public:
	static T		&GetInstance();
	static void		DestroyInstance();

private:
	Singleton<T>	&operator=(const Singleton<T> &);

private:
	static T		*stInstance;
};

template <typename T>
T *Singleton<T>::stInstance = NULL;

//------------------------------------------------------------------
// Constructor / Destructor
//------------------------------------------------------------------
template <typename T>
Singleton<T>::Singleton()
{
}

template <typename T>
Singleton<T>::Singleton(const Singleton<T> &)
{
}

template <typename T>
Singleton<T>::~Singleton()
{
}

//------------------------------------------------------------------
// Instance
//------------------------------------------------------------------
template <typename T>
T &Singleton<T>::GetInstance()
{
	if (Singleton<T>::stInstance == NULL)
		Singleton<T>::stInstance = new T();
	return *Singleton<T>::stInstance;
}

template <typename T>
void Singleton<T>::DestroyInstance()
{
	delete Singleton<T>::stInstance;
	Singleton<T>::stInstance = NULL;
}

//------------------------------------------------------------------
// Operators
//------------------------------------------------------------------
template <typename T>
Singleton<T> &Singleton<T>::operator=(const Singleton<T> &)
{
	return *this;
}

#endif //!SINGLETON_HPP
